package com.neusoft;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class NewsServlet
 */
@WebServlet("/NewsServlet")
public class NewsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NewsServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*
				//开启cookie后不能使用*，这里使用resquest.getHeader("Origin")获取前端域【请求头】
				response.setHeader("Access-Control-Allow-Origin",request.getHeader("origin") );
				//设置开启cookie
				response.setHeader("Access-Control-Allow-Credentials","true");
				*/
				//从Request作用域中获取属性值
		        System.out.println(request.getAttribute("message"));
		        //从Session作用域中获取属性值
		        System.out.println(request.getSession().getAttribute("message"));
		        //从ServletContext作用域中获取属性值
		        System.out.println(request.getServletContext().getAttribute("message"));
				
				/*PrintWriter out = response.getWriter();
				//.getSession()如果当前有session就获取，如果没有就创建新的
				HttpSession session = request.getSession();
				System.out.println(session.getId());
				
				
				String user = (String)session.getAttribute("user");
				
				if(user!=null){
					out.print("news");
				}else{
					out.print("not logged in");
				}
				
				out.close();*/
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
